From: Anthony Ramine Date: Fri, 1 Dec 2017 01:32:15 +0000 (+0100) Subject: Don't recurse out of CARGO_HOME when looking for workspace root X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~4^2~35^2 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/success//%22http:/www.example.com/cgi/success/?a=commitdiff_plain;h=3ce50d02a99419ea15233139000d42ce9c25c6d0;p=cargo.git Don't recurse out of CARGO_HOME when looking for workspace root This fixes #4765. --- diff --git a/src/cargo/core/workspace.rs b/src/cargo/core/workspace.rs index 3dc50a6f2..dee5b248d 100644 --- a/src/cargo/core/workspace.rs +++ b/src/cargo/core/workspace.rs @@ -333,6 +333,9 @@ impl<'cfg> Workspace<'cfg> { } for path in paths::ancestors(manifest_path).skip(2) { + if self.config.home() == path { + return Ok(None); + } let ances_manifest_path = path.join("Cargo.toml"); debug!("find_root - trying {}", ances_manifest_path.display()); if ances_manifest_path.exists() { diff --git a/src/cargo/util/flock.rs b/src/cargo/util/flock.rs index 9f6ae48ea..0a8887d8b 100644 --- a/src/cargo/util/flock.rs +++ b/src/cargo/util/flock.rs @@ -233,6 +233,18 @@ impl Filesystem { } } +impl PartialEq for Filesystem { + fn eq(&self, other: &Path) -> bool { + self.root == other + } +} + +impl PartialEq for Path { + fn eq(&self, other: &Filesystem) -> bool { + self == other.root + } +} + /// Acquires a lock on a file in a "nice" manner. /// /// Almost all long-running blocking actions in Cargo have a status message diff --git a/tests/workspaces.rs b/tests/workspaces.rs index c90464318..19214dbd0 100644 --- a/tests/workspaces.rs +++ b/tests/workspaces.rs @@ -1700,6 +1700,54 @@ fn dep_used_with_separate_features() { ")); } +#[test] +fn dont_recurse_out_of_cargo_home() { + let git_project = git::new("dep", |project| { + project + .file("Cargo.toml", r#" + [package] + name = "dep" + version = "0.1.0" + "#) + .file("src/lib.rs", "") + .file("build.rs", r#" + use std::env; + use std::path::Path; + use std::process::{self, Command}; + + fn main() { + let cargo = env::var_os("CARGO").unwrap(); + let cargo_manifest_dir = env::var_os("CARGO_MANIFEST_DIR").unwrap(); + let output = Command::new(cargo) + .args(&["metadata", "--format-version", "1", "--manifest-path"]) + .arg(&Path::new(&cargo_manifest_dir).join("Cargo.toml")) + .output() + .unwrap(); + if !output.status.success() { + eprintln!("{}", String::from_utf8(output.stderr).unwrap()); + process::exit(1); + } + } + "#) + }).unwrap(); + let p = project("lib") + .file("Cargo.toml", &format!(r#" + [package] + name = "lib" + version = "0.1.0" + + [dependencies.dep] + git = "{}" + + [workspace] + "#, git_project.url())) + .file("src/lib.rs", ""); + let p = p.build(); + + assert_that(p.cargo("build").env("CARGO_HOME", p.root().join(".cargo")), + execs().with_status(0)); +} + /*FIXME: This fails because of how workspace.exclude and workspace.members are working. #[test] fn include_and_exclude() {